﻿using MobileBSC_Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;
using System.Configuration;

namespace MobileBSC_SQLite
{
    public class PerspectiveReader
    {
        private const string SELECT_STMT =
            "SELECT " +
                 "PerspectiveID " +
               ", Name " +
               ", Description " +
            "FROM Perspective ";

        public Perspective ReadByID(long id)
        {
            var statement = SELECT_STMT + "WHERE PerspectiveID = @id;";
            var parameters = new List<SQLiteParameter>();
            parameters.Add(new SQLiteParameter("@id", id));

            return DbTool<Perspective>.ReadSingle(statement, parameters, CreatePerspective);
        }
        public List<Perspective> ReadAll()
        {
            var statement = SELECT_STMT + ";";

            return DbTool<Perspective>.ReadMultiple(statement, null, CreatePerspective);
        }
        private Perspective CreatePerspective(SQLiteDataReader rd)
        {
            Perspective result = new Perspective();
            result.ID = (long)rd["PerspectiveID"];
            result.Name = (string)rd["Name"];
            if (rd.IsDBNull(rd.GetOrdinal("Description")))
                result.Description = "";
            else
                result.Description = (string)rd["Description"];

            return result;
        }
    }
}
